from concurrent import futures
import logging
import time
import grpc
import test_pb2
import test_pb2_grpc


class StreamTest(test_pb2_grpc.StreamTestServicer):
    def ServerStream(self, request, context):
        print("request= ", request)
        message_list = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
        for i in message_list:
            time.sleep(1)
            print("send: ", i)
            yield test_pb2.response(message=i)


def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    test_pb2_grpc.add_StreamTestServicer_to_server(StreamTest(), server)
    server.add_insecure_port("0.0.0.0:10086")
    server.start()
    server.wait_for_termination()


if __name__ == "__main__":
    logging.basicConfig()
    serve()

